package io.renren.modules.merchant.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import io.renren.modules.dishes.entity.MerchantEntity;
import io.renren.modules.merchant.dao.MerchantDao;
import io.renren.modules.merchant.service.MerchantService;
import io.renren.modules.merchant.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import static io.renren.common.utils.ShiroUtils.getUserId;

@Service
public class MessageServiceImpl implements MessageService {

    @Autowired
    private MerchantDao merchantDao;

    @Autowired
    private MerchantService merchantService;
    /**
     * 获取店铺信息
     * @return
     */
    public MerchantEntity getMerchantMessage() {
        Long userId = getUserId();
        String merchantId = merchantService.getMerchantByUserId(userId).getMerchantId();

        return merchantDao.getMerchantMessage(merchantId);
    }

    /**
     * 更新店铺营业状态
     * @param merchantStatus
     */
    public void updateMerchantStatus(Integer merchantStatus) {
        Long userId = getUserId();
        String merchantId = merchantService.getMerchantByUserId(userId).getMerchantId();
        UpdateWrapper updateWrapper = new UpdateWrapper();
        updateWrapper.eq("merchant_id",merchantId);
        updateWrapper.set("merchant_status",merchantStatus);
        MerchantEntity merchant=new MerchantEntity();
        merchantDao.update(merchant,updateWrapper);

    }
}
